package com.ruoyi.web.controller.workSafetyStandardization.rule;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workSafetyStandardization.domain.Deduct;
import com.ruoyi.workSafetyStandardization.service.IDeductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评分-扣分项Controller
 *
 * @author pengjie
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/secure/securerule/deduct")
public class DeductController extends BaseController
{
    @Autowired
    private IDeductService deductService;

    /**
     * 查询评分-扣分项列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:deduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(Deduct deduct)
    {
        startPage();
        List<Deduct> list = deductService.selectDeductList(deduct);
        return getDataTable(list);
    }

    /**
     * 导出评分-扣分项列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:deduct:export')")
    @Log(title = "评分-扣分项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Deduct deduct)
    {
        List<Deduct> list = deductService.selectDeductList(deduct);
        ExcelUtil<Deduct> util = new ExcelUtil<Deduct>(Deduct.class);
        util.exportExcel(response, list, "评分-扣分项数据");
    }

    /**
     * 获取评分-扣分项详细信息
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:deduct:query')")
    @GetMapping(value = "/{deductId}")
    public AjaxResult getInfo(@PathVariable("deductId") String deductId)
    {
        return success(deductService.selectDeductByDeductId(deductId));
    }

    /**
     * 新增评分-扣分项
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:deduct:add')")
    @Log(title = "评分-扣分项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Deduct deduct)
    {
        return toAjax(deductService.insertDeduct(deduct));
    }

    /**
     * 修改评分-扣分项
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:deduct:edit')")
    @Log(title = "评分-扣分项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Deduct deduct)
    {
        return toAjax(deductService.updateDeduct(deduct));
    }

    /**
     * 删除评分-扣分项
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:deduct:remove')")
    @Log(title = "评分-扣分项", businessType = BusinessType.DELETE)
	@GetMapping("/delete")
    public AjaxResult remove(@Param("deductId") String deductId)
    {
        String[] deductIds ={deductId};
        return toAjax(deductService.deleteDeductByDeductIds(deductIds));
    }
}
